home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / LITTLE / BMSRC.ZIP / DOOM.S < prev    next >
Encoding:
Text File  |  1997-02-02  |  22.0 KB  |  883 lines

  1. *=======================================================*
  2. *    Falcon030 Doom project (Bad Mood) v2.13 alpha    *
  3. *=======================================================*
  4. *    Main core: latest update 25/03/96        *
  5. *=======================================================*
  6.  
  7.     COMMENT        HEAD=7
  8.     OPT        P=68040
  9.     OPT        W-
  10.  
  11. *-------------------------------------------------------*
  12. *    Conditional options                *
  13. *-------------------------------------------------------*
  14.  
  15. ;intel
  16. ;frsb
  17. ;test                    ; enable for pre-defined WAD (debug).
  18. ;debuggable                ; enable for 'soft' safe interrupts.
  19. enable_timing                ; enable for scaled movement
  20. ;show_timing                ; enable for timing information.
  21. use_xmmu
  22.  
  23. *-------------------------------------------------------*
  24. *    Compatibility settings                *
  25. *-------------------------------------------------------*
  26.  
  27. ;compat_level        =    0    ; I don't think so...
  28. compat_level        =    1    ; 16Mhz base Falcons.
  29. ;compat_level        =    2    ; Accelerated Falcons.
  30. ;compat_level        =    3    ; Even more accelerated Falcons.
  31. ;compat_level        =    4    ; MC68040 & super-accelerated Falcons.
  32. ;compat_level        =    99    ; 100% ensured legal DSP handshaking.
  33.  
  34. *-------------------------------------------------------*
  35. *    Display settings                *
  36. *-------------------------------------------------------*
  37.  
  38. max_xres        =    320
  39. max_yres        =    200
  40.  
  41. ;bg_colour        =    $000000
  42. bg_colour        =    $101010
  43.  
  44. ;default_width        =    320    ; default width
  45. ;default_height        =    168    ; vertical normal mode (status bar)
  46. ;expanded_height    =    200    ; vertical fullscreen mode
  47. ;base_aspect        =    200    ; base reference (unadjusted) ratio.
  48. ;vga_aspect        =    200    ; 240-line aspect ratio (VGA).
  49. ;rgb_aspect        =    168    ; 200-line aspect ratio (PAL).
  50.  
  51. ;default_width        =    320/2            ; PHYS image width
  52. ;default_height        =    (168*128)/200        ; PHYS image height
  53. ;expanded_height        =    (200*128)/200        ; PHYS image height (expanded)
  54. ;base_aspect        =    (200*100)/200        ; VIRT height rel. to PHYS width (8:5 ratio)
  55. ;vga_aspect        =    (200*100)/200        ; relative VGA aspect ratio
  56. ;rgb_aspect        =    (168*100)/200        ; relative RGB aspect ratio
  57.  
  58. *-------------------------------------------------------*
  59.  
  60. base_red        =    255
  61. base_green        =    255
  62. base_blue        =    255
  63.  
  64. *-------------------------------------------------------*
  65. *    Keycodes for control & player movement        *
  66. *-------------------------------------------------------*
  67. *    These should go away once the event-based    *
  68. *    keyboard routines are ready.            *
  69. *-------------------------------------------------------*
  70.  
  71. rise_key        =    2
  72. drop_key        =    3
  73. hres_key        =    4
  74. vres_key        =    5
  75. text_key        =    28
  76.  
  77. rgb_key            =    19
  78. vga_key            =    47
  79. full_key        =    33
  80. snap_key        =    102
  81.  
  82. quit_key        =    1    ; 'ESC' key
  83. map_key            =    15    ; 'TAB' key
  84.  
  85. minus_key        =    12    ;
  86. plus_key        =    13    ;
  87.  
  88. left_key        =    $4b    ; left arrow
  89. right_key        =    $4d    ; right arrow
  90. forward_key        =    $48    ; up arrow
  91. back_key        =    $50    ; down arrow
  92. alt_key            =    $38    ; 'ALT' key
  93.  
  94. lshift_key        =    42
  95. rshift_key        =    54
  96.  
  97. cookie_jar        =    $5a0
  98.  
  99. *-------------------------------------------------------*
  100. *    Main program includes                *
  101. *-------------------------------------------------------*
  102.  
  103.     include        include\header.s
  104.     include        include\macros.s
  105.     include        include\video.s
  106.     include        pmmu.s
  107.  
  108. *-------------------------------------------------------*
  109. *    DSP core includes                *
  110. *-------------------------------------------------------*
  111.  
  112.     include        include\dspconst.s
  113.     
  114. *-------------------------------------------------------*
  115. *    Mark TEXT, DATA & BSS reference sections    *
  116. *-------------------------------------------------------*
  117.     bss
  118. *-------------------------------------------------------*
  119.     ds.b        8192
  120. *-------------------------------------------------------*
  121. bss_start:
  122. *-------------------------------------------------------*
  123.     data
  124. *-------------------------------------------------------*
  125. data_start:
  126. *-------------------------------------------------------*
  127.     text
  128. *-------------------------------------------------------*
  129. text_start:
  130. *-------------------------------------------------------*
  131. *    Path for pre-defined WAD            *    
  132. *-------------------------------------------------------*
  133.     bra        Doom
  134. *-------------------------------------------------------*
  135.  
  136. default_path:        ;dc.b    'l:\wads\doom.wad e4m8'
  137.             ;dc.b    'l:\wads\doom.wad e1m1'
  138.             ;dc.b    'l:\wads\doom.wad e1m6'
  139.             dc.b    'j:\doom1.wad e1m1'
  140.             ;dc.b    'l:\wads\doom2.wad map01'
  141.             ;dc.b    'l:\wads\heretic1.wad e1m4'
  142.             ;dc.b    'j:\heretic1.wad e1m5'
  143.  
  144.             ;dc.b    '-i l:\wads\doom.wad -p l:\wads\alpha.wad'
  145.  
  146.             ;dc.b    '-i l:\wads\doom2.wad -p l:\wads\scorpion.wad -w map01'
  147.             ;dc.b    '-i l:\wads\doom.wad -p l:\wads\uac_dead.wad -w e1m8'
  148.             ;dc.b    '-i l:\wads\doom2.wad -w map01'
  149.             ;dc.b    '-i l:\wads\doom2.wad -w map11'
  150.             ;dc.b    '-i l:\wads\doom.wad -w e1m1'
  151.  
  152.             dc.b    0
  153.             ds.b    255
  154.  
  155. iwad_path:        ds.b    256
  156. pwad_path:        ds.b    256
  157. levelmarker:        ds.b    8
  158.  
  159. *-------------------------------------------------------*
  160. *    Program starts here                *    
  161. *-------------------------------------------------------*
  162.     txtlong
  163. *-------------------------------------------------------*
  164. Doom:    move.l        4(sp),a5
  165.     lea        128(a5),a4    ; command string
  166.     move.l        a4,cli
  167. *-------------------------------------------------------*
  168. *    Mshrink                        *
  169. *-------------------------------------------------------*
  170.     move.l        12(a5),d0    ; text segment
  171.     add.l        20(a5),d0    ; data segment
  172.     add.l        28(a5),d0    ; bss segment
  173.     add.l        #256,d0        ; base page
  174.     lea        usp_stack,sp
  175.     move.l        d0,-(sp)
  176.     move.l        a5,-(sp)
  177.     clr.w        -(sp)
  178.     move.w        #$4a,-(sp)
  179.     trap        #1
  180.     lea        12(sp),sp
  181. *-------------------------------------------------------*
  182. *    Flush out BSS                    *
  183. *-------------------------------------------------------*
  184.     jsr        clear_bss
  185. *-------------------------------------------------------*
  186. *    Flush keyboard buffer                *
  187. *-------------------------------------------------------*
  188.     bsr        empty_buffer
  189. *-------------------------------------------------------*
  190. *    Commandline module                *
  191. *-------------------------------------------------------*
  192.     bsr        parse_cli
  193. *-------------------------------------------------------*
  194. *    Find size of system display area        *
  195. *-------------------------------------------------------*
  196.     jsr        appl_init
  197.     jsr        graf_handle
  198.     jsr        v_opnvwk
  199.     jsr        v_extnd
  200.     jsr        v_hidemouse
  201.     move.w        vwork_w,os_screen_w
  202.     move.w        vwork_h,os_screen_h
  203. *-------------------------------------------------------*
  204. *    Check for bad monitor types            *
  205. *-------------------------------------------------------*
  206.     jsr        monitor_detect
  207.     tst.w        d0
  208.     beq        safe_quit
  209. *-------------------------------------------------------*
  210. *    Initialise internal memory manager        *
  211. *-------------------------------------------------------*
  212.     bsr        init_block_manager
  213. *-------------------------------------------------------*
  214. *    Parse Doom WAD files                *
  215. *-------------------------------------------------------*
  216.     move.l        #hash_space,hash_array
  217.     bsr        parse_iwad
  218.     bsr        parse_pwad
  219.     Cconws        #ascii_entriesdone
  220. *-------------------------------------------------------*
  221. *    Integrate PWAD into main IWAD directory        *
  222. *-------------------------------------------------------*
  223.     bsr        integrate_wads
  224. *-------------------------------------------------------*
  225. *    Load level resources                *
  226. *-------------------------------------------------------*
  227.     bsr        load_leveldata
  228. *-------------------------------------------------------*
  229. *    Initialise textures & colourmaps        *
  230. *-------------------------------------------------------*
  231.     bsr        init_textures
  232.     bsr        init_cache
  233.     bsr        init_colours
  234.     bsr        thrash_level
  235.     Cconws        #ascii_replacedone
  236. *-------------------------------------------------------*
  237. *    Precalculate wall lengths            *
  238. *-------------------------------------------------------*
  239.     bsr        measure_linedefs
  240. *-------------------------------------------------------*
  241. *    Wad parsing complete - close wadfile & pause    *
  242. *-------------------------------------------------------*
  243.     bsr        close_wad
  244.     Crawcin
  245. *-------------------------------------------------------*
  246. *    Switch to supervisor mode            *
  247. *-------------------------------------------------------*
  248.     pea        ssp_stack
  249.     push.w        #32
  250.     trap        #1
  251.     move.l        d0,os_ssp_ptr
  252. *-------------------------------------------------------*
  253. *    Setup new truecolour video mode            *
  254. *-------------------------------------------------------*
  255.     jsr        save_screen
  256.     jsr        save_palette
  257.     jsr        default_video
  258.     jsr        configure_viewport
  259.     move.b        clearcount,refresh
  260. *-------------------------------------------------------*
  261. *    Mark MMU pages for extra speed on 68040        *
  262. *-------------------------------------------------------*
  263.     jsr        initialise_pmmu
  264. *-------------------------------------------------------*
  265. *    Kickstart DSP Doom Core                *
  266. *-------------------------------------------------------*
  267.     bsr        kickstart_doomcore
  268. *-------------------------------------------------------*
  269. *    Select initial window size & prepare lists    *
  270. *-------------------------------------------------------*
  271.     move.w        #window_max,window_size
  272.     bsr        select_window
  273. *-------------------------------------------------------*
  274. *    Set up global display structure            *
  275. *-------------------------------------------------------*
  276.     bsr        init_displaystruct
  277. *-------------------------------------------------------*
  278. *    Enable VBI & timing interrupts            *
  279. *-------------------------------------------------------*
  280.     bsr        init_timing
  281. *-------------------------------------------------------*
  282. *    Replace keyboard handler            *
  283. *-------------------------------------------------------*
  284.     bsr        initialise_ikbd
  285. *-------------------------------------------------------*
  286. *    Open WAD file, prepare for access        *
  287. *-------------------------------------------------------*
  288.     bsr        open_wad
  289. *-------------------------------------------------------*
  290. *    Main program loop                *
  291. *-------------------------------------------------------*
  292. game_loop:
  293. *-------------------------------------------------------*
  294. ;    move.w        $FFFF82C2.w,d0
  295. ;    bset        #0,d0
  296. ;    move.w        d0,$FFFF82C2.w
  297. *-------------------------------------------------------*
  298. *    Read keyboard (debug mode only)            *
  299. *-------------------------------------------------------*
  300.     ifd        debuggable
  301.     bsr        read_key
  302.     endc
  303. *-------------------------------------------------------*
  304. *    Move player                     *
  305. *-------------------------------------------------------*
  306.     bsr        player_control
  307. *-------------------------------------------------------*
  308. *    Get player direction                *    
  309. *-------------------------------------------------------*
  310.     bsr        triangulate
  311. *-------------------------------------------------------*
  312. *    Display 3D environment                *
  313. *-------------------------------------------------------*
  314.     bsr        display_engine
  315. *-------------------------------------------------------*
  316. *    Display level map                *    
  317. *-------------------------------------------------------*
  318.     bsr        display_map
  319. *-------------------------------------------------------*
  320. *    Display framerate in corner of screen        *
  321. *-------------------------------------------------------*
  322.     ifd        enable_timing
  323.     bsr        timing
  324.     endc
  325. *-------------------------------------------------------*
  326. *    Double-buffered display                *
  327. *-------------------------------------------------------*
  328.     vsync
  329.     bsr        adjust_scanlines
  330. *-------------------------------------------------------*
  331.     ifd        frsb
  332. *-------------------------------------------------------*
  333.     move.l        ScreenLog,a0
  334.     move.l        ScreenPhy,a1
  335.  
  336.     move.w        width,d7
  337.     tst.b        halfrows
  338.     beq.s        .nhr
  339.     add.w        d7,d7
  340. .nhr:
  341.     move.w        scrwidth,d0
  342.     lsr.w        d0
  343.  
  344.     move.w        d7,d1
  345.     lsr.w        d1
  346.     sub.w        d1,d0
  347.     lsr.w        #3,d0        ; d0 = dphrase start
  348.     move.w        d0,d6
  349.     lsl.w        #3,d6
  350.     add.w        d7,d6
  351.     addq.w        #8-1,d6
  352.     lsr.w        #3,d6        ; d6 = qphrase end
  353.     sub.w        d0,d6        ; qphrase length
  354.     lsl.w        #3+1,d0
  355.     add.w        d0,a0
  356.     add.w        d0,a1
  357.     move.w        height,d7
  358.     move.w        scrwidth,a2
  359.     add.l        a2,a2
  360.     move.w        d6,d5
  361.     lsl.w        #3+1,d5
  362.     sub.w        d5,a2
  363.     subq.w        #1,d6
  364.     subq.w        #1,d7
  365. .yl:    move.w        d6,d0
  366. .xl:    move16        (a0)+,(a1)+
  367.     dbra        d0,.xl
  368.     add.l        a2,a0
  369.     add.l        a2,a1
  370.     dbra        d7,.yl
  371. *-------------------------------------------------------*
  372.     elseif
  373. *-------------------------------------------------------*
  374.     doublebuffer
  375. *-------------------------------------------------------*
  376.     endc
  377. *-------------------------------------------------------*
  378. *    Check for exit key                *
  379. *-------------------------------------------------------*
  380.     tst.b        program_quit
  381.     beq        game_loop
  382.  
  383. *-------------------------------------------------------*
  384. *    Program end - restore parameters & exit        *
  385. *-------------------------------------------------------*
  386. game_exit:
  387. *-------------------------------------------------------*
  388. *    Restore system                    *
  389. *-------------------------------------------------------*
  390.     bsr        close_wad
  391.     bsr        empty_buffer
  392.     bsr        remove_ikbd
  393.     bsr        reset_timing
  394.     jsr        restore_screen
  395.     jsr        restore_palette
  396.     jsr        restore_pmmu
  397.     bsr        empty_buffer
  398. *-------------------------------------------------------*
  399. *    Return to user mode                *
  400. *-------------------------------------------------------*
  401.     push.l        os_ssp_ptr
  402.     move.w        #32,-(sp)
  403.     trap        #1
  404.     addq.l        #6,sp
  405. *-------------------------------------------------------*
  406. *    Exit program                    *
  407. *-------------------------------------------------------*
  408. safe_quit:
  409. *-------------------------------------------------------*
  410.     jsr        v_showmouse
  411.     jsr        v_clsvwk
  412.     jsr        appl_exit
  413. *-------------------------------------------------------*
  414. *    Terminate program                *
  415. *-------------------------------------------------------*
  416.     clr.w        -(sp)
  417.     trap        #1
  418.  
  419. *-------------------------------------------------------*
  420. *    Player control module with turning & movement    *
  421. *-------------------------------------------------------*
  422.     txtlong
  423. *-------------------------------------------------------*
  424. player_control:
  425. *-------------------------------------------------------*
  426.     lea        key_buffer,a6
  427.  
  428.     tst.b        rgb_key(a6)
  429.     beq.s        .nrgb
  430.     move.w        sys_rgb_aspect,aspect_ratio
  431. ;    move.w        #rgb_aspect,aspect_ratio
  432.     bsr        select_window
  433. .nrgb:
  434.     tst.b        vga_key(a6)
  435.     beq.s        .nvga
  436.     move.w        sys_vga_aspect,aspect_ratio
  437. ;    move.w        #vga_aspect,aspect_ratio
  438.     bsr        select_window
  439. .nvga:
  440.     tst.b        full_key(a6)
  441.     beq.s        .nf
  442.     move.w        sys_expanded_height,viewport_height
  443. ;    move.w        #expanded_height,viewport_height
  444.     not.b        fullscreen
  445.     bne.s        .nf1
  446.     move.w        sys_default_height,viewport_height
  447. ;    move.w        #default_height,viewport_height
  448. .nf1:    bsr        select_window
  449. .nf:
  450.     
  451. ;    tst.b        text_key(a6)
  452. ;    beq.s        .ntx
  453. ;    bsr        texture_loop
  454. ;.ntx:
  455.     tst.b        hres_key(a6)
  456.     beq.s        .ndh
  457.     jsr        toggle_h_detail
  458. .ndh:
  459.     tst.b        vres_key(a6)
  460.     beq.s        .ndv
  461.     jsr        toggle_v_detail
  462. .ndv:
  463.  
  464.  
  465.     tst.b        plus_key(a6)
  466.     beq.s        .nwp
  467.     add.w        #32,window_size
  468.     bsr        select_window
  469. .nwp:    tst.b        minus_key(a6)
  470.     beq.s        .nwm
  471.     sub.w        #32,window_size
  472.     bsr        select_window
  473. .nwm:    tst.b        quit_key(a6)
  474.     beq.s        .nox
  475.     st        program_quit
  476. .nox:    tst.b        map_key(a6)
  477.     beq.s        .nmk
  478.     not.b        map_enabled
  479. .wlp:    tst.b        map_key(a6)
  480.     bne.s        .wlp
  481. .nmk:
  482.     tst.b        snap_key(a6)
  483.     beq.s        .nss
  484.     bsr        save_snapshot
  485. .nss:
  486.     rts
  487.  
  488. save_snapshot:
  489.  
  490.     pushall
  491.  
  492.     move.w        height,d0
  493.     mulu.w        screen_w,d0
  494.     move.l        d0,snap_pixels
  495.     mulu.l        #3,d0
  496.     add.l        #18,d0
  497.     move.l        d0,snap_size
  498.  
  499.     moveq        #VRAM_preferred,d1
  500.     bsr        allocate_chunk
  501.     tst.l        d0
  502.     ble        .err
  503.     move.l        d0,snap_handle
  504.     move.l        d0,a1
  505.     
  506.     lea        tga_header,a2
  507.     move.w        screen_w,d0
  508.     ror.w        #8,d0
  509.     move.w        d0,12(a2)
  510.     move.w        height,d0
  511.     ror.w        #8,d0
  512.     move.w        d0,14(a2)
  513.     move.w        #(18/2)-1,d0
  514. .hdr:    move.w        (a2)+,(a1)+
  515.     dbra        d0,.hdr
  516.     
  517.     move.l        ScreenPhy,a0
  518.  
  519.     move.l        snap_pixels,d4
  520. .all:    move.w        (a0)+,d0
  521.     bfextu        d0{16:08},d1
  522.     bfextu        d0{21:08},d2
  523.     bfextu        d0{27:08},d3
  524.     and.b        #%11111000,d1
  525.     and.b        #%11111100,d2
  526.     and.b        #%11111000,d3
  527.     move.b        d3,(a1)+
  528.     move.b        d2,(a1)+
  529.     move.b        d1,(a1)+
  530.     subq.l        #1,d4
  531.     bne.s        .all
  532.  
  533.     push.w        #0
  534.     pea        snap_name
  535.     push.w        #60
  536.     trap        #1
  537.     addq.l        #8,sp
  538.     move.l        d0,d7
  539.     bmi.s        .ferr
  540.  
  541.     push.l        snap_handle
  542.     push.l        snap_size
  543.     push.w        d7
  544.     push.w        #64
  545.     trap        #1
  546.     lea        12(sp),sp
  547.     
  548.     push.w        d7
  549.     push.w        #62
  550.     trap        #1
  551.     addq.l        #4,sp
  552.     
  553. .ferr:
  554.  
  555.     move.l        snap_handle,d0
  556.     bsr        deallocate_chunk
  557.  
  558. .err:    popall
  559.     rts
  560.  
  561. player_movement:
  562.     lea        key_buffer,a6
  563.  
  564.     move.l        #rotate_speed,d5
  565.     move.l        #slide_speed,d6
  566.     move.l        #walk_speed,d7
  567.  
  568.     tst.b        lshift_key(a6)
  569.     bne.s        .ys
  570.     tst.b        rshift_key(a6)
  571.     beq.s        .ns
  572. .ys:    add.l        d5,d5
  573.     add.l        d6,d6
  574.     add.l        d7,d7
  575. .ns:
  576.  
  577.     tst.b        rise_key(a6)
  578.     beq.s        .nr
  579.     addq.w        #4,pho
  580. .nr:    tst.b        drop_key(a6)
  581.     beq.s        .nd
  582.     subq.w        #4,pho
  583. .nd:
  584.     tst.b        left_key(a6)
  585.     beq.s        .not_left
  586.     tst.b        alt_key(a6)
  587.     bne.s        .slide_left
  588.     add.l        d5,pangle
  589.     bra.s        .not_left
  590. .slide_left:
  591.     add.l        d6,right_speed
  592. .not_left:
  593.     tst.b        right_key(a6)
  594.     beq.s        .not_right
  595.     tst.b        alt_key(a6)
  596.     bne.s        .slide_right
  597.     sub.l        d5,pangle
  598.     bra.s        .not_right
  599. .slide_right:
  600.     sub.l        d6,right_speed
  601. .not_right:
  602.     tst.b        forward_key(a6)
  603.     beq.s        .not_forward
  604.     add.l        d7,front_speed
  605. .not_forward:
  606.     tst.b        back_key(a6)
  607.     beq.s        .not_back
  608.     sub.l        d7,front_speed
  609. .not_back:
  610.     move.w        mouse_dy,d0
  611.     beq.s        .no_mouse_y
  612.     clr.w        mouse_dy
  613.     ext.l        d0
  614.     muls.l        #walk_speed,d0
  615.     asr.l        d0
  616.     move.l        d0,d1
  617.     asr.l        #1,d1
  618.     sub.l        d1,d0
  619.     sub.l        d0,front_speed    
  620. .no_mouse_y:
  621.     move.w        mouse_dx,d0
  622.     beq.s        .no_mouse_x
  623.     clr.w        mouse_dx
  624.     ext.l        d0
  625.     cmp.b        #1,buttons
  626.     bne.s        .rotate
  627.     muls.l        #slide_speed,d0
  628.     asr.l        d0
  629.     move.l        d0,d1
  630.     asr.l        #1,d1
  631.     sub.l        d1,d0
  632.     sub.l        d0,right_speed    
  633.     bra.s        .no_mouse_x
  634. .rotate:
  635.     muls.l        #rotate_speed,d0
  636.     asr.l        #3,d0
  637.     move.l        d0,d1
  638.     asr.l        #2,d1
  639.     sub.l        d1,d0
  640.     sub.l        d0,pangle
  641. .no_mouse_x:
  642.     move.l        right_speed,d0
  643.     beq.s        .no_right
  644.     move.w        #right_angle,d1
  645.     bsr        move_player
  646.     lea        right_speed,a0
  647.     bsr        decay_speed
  648. .no_right:
  649.     move.l        front_speed,d0
  650.     beq.s        .no_front
  651.     move.w        #front_angle,d1
  652.     bsr        move_player
  653.  
  654.     move.l        front_speed,d0
  655.     add.l        bob_shift,d0
  656.     move.l        d0,bob_shift
  657.  
  658.     move.l        d0,d1
  659.     lsl.l        #4,d0
  660.     lsl.l        #3,d1
  661.     add.l        d1,d0
  662.     lsr.l        d1
  663.     add.l        d1,d0
  664.  
  665.     swap        d0
  666.     and.w        #sinres-1,d0
  667.     move.w        (sine.l,d0.w*2),d0
  668.     asr.w        #8,d0
  669.     asr.w        #4,d0
  670.     move.w        d0,pho
  671.  
  672.     lea        front_speed,a0
  673.     bsr        decay_speed
  674. .no_front:
  675.     rts
  676.  
  677. decay_speed:
  678.     move.l        (a0),d0
  679.     bmi.s        .neg    
  680.     move.l        d0,d1
  681.     lsr.l        #2,d0
  682.     sub.l        d0,d1
  683.     and.l        #-128,d1
  684.     move.l        d1,(a0)
  685.     rts
  686. .neg:    neg.l        d0
  687.     move.l        d0,d1
  688.     lsr.l        #2,d0
  689.     sub.l        d0,d1
  690.     and.l        #-128,d1
  691.     neg.l        d1
  692.     move.l        d1,(a0)
  693.     rts
  694.  
  695.  
  696. bob_shift:    ds.l    1
  697.  
  698.     rept        0
  699.  
  700.     tst.b        left_key(a6)
  701.     beq.s        not_left
  702.     tst.b        alt_key(a6)
  703.     bne.s        move_left
  704.     add.w        #turn_speed,pangle
  705.     bra.s        not_left
  706. move_left:
  707.     move.w        #$4000,d1
  708.     move.w        #player_speed,d0
  709.     bsr        move_player
  710. not_left:
  711.     tst.b        right_key(a6)
  712.     beq.s        not_right
  713.     tst.b        alt_key(a6)
  714.     bne.s        move_right
  715.     sub.w        #turn_speed,pangle
  716.     bra.s        not_right
  717. move_right:
  718.     move.w        #$4000,d1
  719.     move.w        #-player_speed,d0
  720.     bsr        move_player
  721. not_right:
  722.     tst.b        forward_key(a6)
  723.     beq.s        not_forward
  724.     move.w        #player_speed,d0
  725.     moveq        #0,d1
  726.     bsr        move_player
  727. not_forward:
  728.     tst.b        back_key(a6)
  729.     beq.s        not_back
  730.     move.w        #-player_speed,d0
  731.     moveq        #0,d1
  732.     bsr        move_player
  733. not_back:
  734.     move.w        mouse_dy,d0
  735.     beq        no_mouse_y
  736.     neg.w        d0
  737.     moveq        #0,d1
  738.     bsr        move_player
  739.     clr.w        mouse_dy
  740. no_mouse_y:
  741.     move.w        mouse_dx,d0
  742.     beq        no_mouse_x
  743.     cmp.b        #1,buttons
  744.     bne.s        rotate
  745.     neg.w        d0
  746.     move.w        #$4000,d1
  747.     bsr        move_player
  748.     bra.s        no_mouse_x
  749. rotate:
  750.     move.w        mouse_dx,d0
  751.     asl.w        #5,d0
  752.     sub.w        d0,pangle
  753. no_mouse_x:
  754.     clr.w        mouse_dx
  755.  
  756.     endr
  757.     
  758.     rts
  759.  
  760. *-------------------------------------------------------*
  761. * Generic movement routine -    d0 = distance        *
  762. *                d1 = angle offset    *
  763. *-------------------------------------------------------*
  764.     txtlong
  765. *-------------------------------------------------------*
  766. move_player:
  767. *-------------------------------------------------------*
  768.     lsl.l        #2,d0
  769.     move.l        d0,d2            ; save distance for later 
  770.     add.w        pangle,d1
  771.     lsr.w        #(16-12),d1
  772.     move.w        (sine.l,d1.w*2),d3
  773.     ext.l        d3
  774.     muls.l        d3,d3:d0
  775.     move.w        d3,d0
  776.     swap        d0
  777.     add.w        #sinres/4,d1
  778.     and.w        #sinres-1,d1
  779.     move.w        (sine.l,d1.w*2),d3
  780.     ext.l        d3
  781.     muls.l        d3,d3:d2
  782.     move.w        d3,d2
  783.     swap        d2
  784.     add.l        d0,py
  785.     add.l        d2,px
  786.     rts
  787.  
  788. *-------------------------------------------------------*
  789. *    Convert rotational angle into a vector        *
  790. *-------------------------------------------------------*
  791.     txtlong
  792. *-------------------------------------------------------*
  793. triangulate:
  794. *-------------------------------------------------------*
  795.     move.w        pangle,d0
  796.     andi.l        #$ffff,d0    
  797.     neg.l        d0
  798.     lsr.w        #(16-12),d0
  799.     lea        sine,a0
  800.     move.w        (a0,d0.w*2),d1
  801.     add.w        #sinres/4,d0
  802.     and.w        #sinres-1,d0
  803.     ext.l        d1
  804.     lsl.l        #2,d1
  805.     move.l        d1,sinpangle
  806.     move.w        (a0,d0.w*2),d1
  807.     ext.l        d1
  808.     lsl.l        #2,d1
  809.     move.l        d1,cospangle
  810.     rts
  811.     
  812.     
  813. *-------------------------------------------------------*
  814. *    Program modules                    *
  815. *-------------------------------------------------------*
  816.  
  817.     include        io.s
  818.     include        levelmap.s
  819.     include        keyboard.s
  820.     include        screen.s
  821.     include        textures.s
  822.     include        engine.s
  823.     include        memory.s
  824.     include        cache.s
  825.     include        sys.s
  826.     include        68040.s
  827.  
  828. *-------------------------------------------------------*
  829.             datlong
  830. *-------------------------------------------------------*
  831.  
  832. tga_header:        incbin    'data\tga.dat'
  833.  
  834. snap_name:        dc.b    'doomshot.tga',0
  835.             even
  836.  
  837. *-------------------------------------------------------*
  838.             bsslong
  839. *-------------------------------------------------------*
  840.  
  841.  
  842. px:            ds.l    1        ; player-x
  843. py:            ds.l    1        ; player-y
  844. pho:            ds.w    1        ; player height offset (for flying)
  845. pangle:            ds.l    1        ; player direction
  846. cospangle:        ds.l    1        ; Cos[d]
  847. sinpangle:        ds.l    1        ; Sin[d]
  848.  
  849. right_speed:        ds.l    1
  850. front_speed:        ds.l    1
  851.  
  852. snap_handle:        ds.l    1
  853. snap_size:        ds.l    1
  854. snap_pixels:        ds.l    1
  855.  
  856. program_quit:        ds.b    1        ; exit flag
  857.  
  858. string_space:        ds.b    256        ; general string space
  859.  
  860. *-------------------------------------------------------*
  861.             bsslong
  862. *-------------------------------------------------------*
  863. bss_end:
  864. *-------------------------------------------------------*
  865.  
  866. *-------------------------------------------------------*
  867. *    Special system areas                *
  868. *-------------------------------------------------------*
  869.  
  870. os_ssp_ptr:        ds.l    1
  871.  
  872. cli:            ds.l    1        ; command line pointer
  873.  
  874.             ds.b    1024
  875. usp_stack:        even
  876.  
  877.             ds.b    4096
  878. ssp_stack:        even
  879.  
  880. *-------------------------------------------------------*
  881. bss_all_end:        ds.b    8192
  882. *-------------------------------------------------------*
  883.